
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *

from ui.axis_select_positions import Ui_Dialog

from common.libs.logger import logger


class AxisSelectPositionsDialog(QDialog, Ui_Dialog):

    position = 0

    def __init__(self):
        super(AxisSelectPositionsDialog, self).__init__()
        self.setupUi(self)
        self.setWindowTitle("预设位置选择")
        self.pushButton_ok.clicked.connect(self.accept)
        self.pushButton_cancel.clicked.connect(self.reject)

        self.listView.clicked.connect(self.listViewClicked)

    def setPositions(self, positions: list):
        self.positions = positions
        slm = QStringListModel()
        self.qList = ['%s->%s' % (p['name'], p['value']) for p in positions]
        slm.setStringList(self.qList)
        self.listView.setModel(slm)

    def listViewClicked(self, qModelIndex):
        position = self.qList[qModelIndex.row()]
        self.position = position.split('->')[-1]
        self.label_position.setText(self.position)
        # QMessageBox.information(self, "QListView", "你选择了: "+ self.qList[qModelIndex.row()])

    def accept(self):
        QDialog.accept(self)

    def reject(self):
        QDialog.reject(self)







